<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <link href="../../../static/css/style.css" rel="stylesheet" type="text/css"/>
</head>

<body>
<div class="place"><span>位置：</span>
    <ul class="placeul">
        <li>仓库管理</li>
        <li>仓库管理</li>
        <li>添加仓库</li>
    </ul>
</div>
<div class="formbody">
    <div class="formtitle"><span>仓库信息</span></div>
    <form id="systemForm" action="" method="get">
        <table>
        <ul class="forminfo" >
            <li>
                <label>仓库名称</label>
                <input name="cName" maxlength="30" type="text" class="dfinput"/>
                <i>必填，不能超过30个字符</i>
            </li>
            <li>
                <label>仓库地址</label>
                <input name="cAddress" maxlength="50" type="text" class="dfinput"/>
                <i>必填，不能超过300个字符</i>
            </li>
            <li>
                <label>所属</label>
                <select class="province" name="province" onchange="provinceChange()">
                    <!--          <option>请选择</option>-->
                    <!--          <option>北京</option>-->
                    <!--          <option>江苏</option>-->
                    <!--          <option>天津</option>-->
                </select>
                省
                <select class="city" name="city">
                    <!--          <option>请选择</option>-->
                    <!--          <option>北京</option>-->
                    <!--          <option>南京</option>-->
                    <!--          <option>天津</option>-->
                </select>
                市
                <i>必选</i>
            </li>
            <li>
                <label>负责人</label>
                <select class="usre" id="usre" name="usre">
                    <!--          <option>请选择</option>-->
                    <!--          <option>周仓</option>-->
                    <!--          <option>廖化</option>-->
                    <!--          <option>张昭</option>-->
                </select>
                <i>只能是财务部仓库管理员职位</i>
            </li>
            <li>
                <label>联系方式</label>
                <input id="phone" maxlength="16" name="phone" type="text" class="dfinput"/>
                <i>必填，不能超过30个字符</i>
            </li>
            <li>
                <label>描述</label>
                <textarea maxlength="2000" name="details" class="textinput"></textarea>
                <i>可选</i>
            </li>
            <li>
                <label>状态</label>
                <select name="state" class="dfselect">
                    <option value="1">可用</option>
                    <option value="0">不可用</option>
                </select>
                <i>必选</i>
            </li>
            <li>
                <label>创建人</label>
                <input name="users" id="users" type="text" value="马云" readonly="readonly" class="roinput"/>
                <i>不能编辑</i>
            </li>
            <li>
                <label>创建时间</label>
                <input name="creationTime" id="createTime" type="text" value="2017-11-18 15:36:10" readonly="readonly"
                       class="roinput"/>
                <i>不能编辑</i>
            </li>
            <li>
                <label>&nbsp;</label>
                <input id="submitBtn" onclick="submitMessage()" type="button" class="btn" value="确定"/>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a href="/storage/lists"><input type="button" class="btn" value="返回" onclick="window.location.href='/storage/lists'"/></a>
            </li>
        </ul>
        </table>
    </form>
</div>
<script type="text/javascript" src="../../../static/js/jquery.js"></script>
<script>
    $(function () {
        getWarehouseGetUsre();
        getAddressInfo();
    });
    var nowUser = JSON.parse(localStorage.getItem("user"));//当前用户
    $('#users').val(nowUser.uname);

    //加载仓管列表
    function getWarehouseGetUsre() {
        $.ajax({
            url: "/Warehouse/WarehouseGetUsre",
            type: "get",
            dataType: "json",
            success: (pb) => {
                $(".ures").html('<option value="">请选择</option>')
                pb.data.forEach((item, index) => {
                    $(".usre").append(`<option  value="${item.id}">${item.uname}</option>`)
                })
            }
        })
    }

    //全局信息
    window.datas = {
        //地区信息
        addressInfo: [],
    };

    //获取地区信息
    function getAddressInfo() {
        $.ajax({
            url: "/commonProvince",
            type: "get",
            dataType: "json",
            success: (data) => {
                window.datas.addressInfo = data.data;
                $(".province").html('<option value="">请选择省份</option>')
                window.datas.addressInfo.forEach((item, index) => {
                    $(".province").append(`<option name="${item.id}" value="${item.id}">${item.pname}</option>`)
                })

            }
        })
    }

    //选择省份之后
    function provinceChange() {
        let addressInfo = datas.addressInfo;
        let city = [];
        let id = $(".province option:selected").attr("name");
        for (let i = 0; i < addressInfo.length; i++) {
            if (addressInfo[i].id == id) {
                city = addressInfo[i].citys;
                break;
            }
        }
        $(".city").html('<option value="">请选择城市</option>')
        city.forEach((item, index) => {
            $(".city").append(`<option value="${item.id}">${item.cname}</option>`);
        })

    }

    // 当前创建用户
    function getCurrentUser() {
        $.ajax({
            url: "/currentUsers",
            type: "get",
            dataType: "json",
            success: (data) => {
                $("#users").html(data.name);
            }
        })
    }

    //修改时间更新
    timer = setInterval(function () {
        //clearInterval(timer);   //定时器清除；
        let time = new Date();
        let newTime = time.getFullYear() + '-' + (time.getMonth() + 1) + '-' + time.getDate() + ' ' +
            time.getHours() + ':' + time.getMinutes() + ':' + time.getSeconds();
        $("#createTime").val(newTime);
    }, 1000);

    function submitMessage() {
        $('.dfinput').blur()
        if($('.dfinput').val()==null)
            alert("111")
        let nowUserID = nowUser.uid;
        $('#users').val(nowUserID);
        let formArray =$("#systemForm").serializeArray();
        $.ajax({
            url: "/Warehouse/WarehouseAdd",
            type: "get",
            dataType: "json",
            data: formArray,
            success: (data) => {
                // $("#users").html(data);
                alert(data.msg);
            }
        })
        $('#users').val(nowUser.uname);
    }

    //手机号格式验证
    let checkPhone = function PhoneFalse() {
        let pattern = /^1[34578]\d{9}$/;
        if (!pattern.test($(this).val())) {
            $(this).css('border', '1px solid red');
            $(this).select();
        }else {
            $(this).css('border', '1px solid black');
        }
    }
    //失焦，聚焦判断；手机邮箱等正则验证
    $('#phone').blur(checkPhone)

    //判空函数
    let checkEmpty = function () {
        if (!$(this).val()) { //文本域,内容为空则提示输入，
            $(this).css('border', '1px solid red');
        }
    }
    //聚焦选中函数
    let select = function () {
        $(this).css('border', '1px solid gray');
        $(this).select();
    }

    $('.dfinput').blur(checkEmpty)
    $('.dfinput').focus(select)

</script>
</body>
</html>
